package com.example.boot.http.provider.common;

import com.example.boot.http.provider.bean.User;

import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlSeeAlso;

@XmlRootElement(name = "Result")
@XmlSeeAlso({User.class})
public class Result<T> {

    private int code;
    private String message = "success";
    private T data;

    public Result() {
    }

    public void success(T data) {
        this.data = data;
    }

    public void success(String message, T data) {
        this.message = message;
        this.data = data;
    }

    public void fail() {
        fail("fail");
    }

    public void fail(String message) {
        this.code = -1;
        this.message = message;
    }

    public void fail(String message, T data) {
        fail(message);
        this.data = data;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    @Override
    public String toString() {
        return "Result{" +
                "code=" + code +
                ", message='" + message + '\'' +
                ", data=" + data +
                '}';
    }
}
